home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
me_cd.zip
/
PICTURE.MUT
< prev
next >
Wrap
Lisp/Scheme
|
1988-09-07
|
24KB
|
720 lines
;; "Picture mode" -- editing using quarter-plane screen model.
;; Copyright (C) 1985 Free Software Foundation, Inc.
;; Principal author K. Shane Hartman
;; Converted to Mutt 6/88 C Durland
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;; Utilities ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Eliminate whitespace at ends of lines.
(defun remove-trailing-whitespace
{
(arg-prefix 9)(set-mark)
(beginning-of-buffer)
(re-query-replace '\ +$' "")
(arg-prefix 9)(exchange-dot-and-mark)
(msg "Removed trailing whitespace")
})
; move to the next tab stop in the tabs list
(defun tab-to-tab-stop (int num-tabs) (array byte tabs 1)
{
(int i col)
(col (current-column))
(for (i 0) (and (< i num-tabs)(>= col (tabs i))) (+= i 1) ())
(if (< i num-tabs) { (to-col (i (tabs i))) i } col)
})
(include asc.mut)
(include me.h)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;; Picture Movement Commands ;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Move to column in current line.
;; Differs from move-to-column in that it creates or modifies whitespace
;; if necessary to attain exactly the specified column.
(defun move-to-column-force (int column) HIDDEN
{
(current-column column) (to-col column)
})
;; Move forward n lines, creating new ones if needed
(defun pforward-line (int n) HIDDEN
{
(int oo)
(oo (overstrike))(overstrike 1)
(arg-prefix n)(newline)
(overstrike oo)
})
;; Position point after last non-blank character on current line.
;; With ARG not nil, move forward ARG - 1 lines first.
;; If scan reaches end of buffer, stop there without error.
(defun picture-end-of-line
{
(if (arg-flag) (forward-line (- (arg-prefix) 1)))
(end-of-line)
(if (previous-character)
{
(while (isspace) (previous-character))
(next-character)
})
})
;; Move cursor right, making whitespace if necessary.
;; With argument, move that many columns.
(defun picture-forward-column
{
(move-to-column-force (+ (current-column) (arg-prefix)))
})
;; Move cursor left, making whitespace if necessary.
;; With argument, move that many columns.
(defun picture-backward-column
{
(move-to-column-force (- (current-column) (arg-prefix)))
})
;; Move vertically down, making whitespace if necessary.
;; With argument, move that many lines.
(defun picture-move-down
{
(int col)
(col (current-column))
(pforward-line (arg-prefix))
(move-to-column-force col)
})
;; Move vertically up, making whitespace if necessary.
;; With argument, move that many lines.
(defun picture-move-up
{
(int col n)
(n (arg-prefix))
(col (current-column))
(while (>= (-= n 1) 0)
(if (not (forward-line -1)) ; at top of buffer
{ (beginning-of-buffer)(open-line) })
)
(move-to-column-force col)
})
;; Amount to move vertically after text character in Picture mode.
(int picture-vertical-step)
;; Amount to move horizontally after text character in Picture mode.
(int picture-horizontal-step)
;; Set VERTICAL and HORIZONTAL increments for movement in Picture mode.
;; The mode line is updated to reflect the current direction.
(defun picture-set-motion (int vert horiz) HIDDEN
{
(picture-vertical-step vert)
(picture-horizontal-step horiz)
; (setq mode-name
; (format "Picture:%s"
; (car (nthcdr (+ 1 (% horiz 2) (* 3 (1+ (% vert 2))))
; '(nw up ne left none right sw down se)))))
(msg "Picture: "
(switch (+ 1 horiz (* 3 (+ 1 vert)))
0 "NW"
1 "up"
2 "NE"
3 "left"
4 "none"
5 "right"
6 "SW"
7 "down"
8 "SE"
)
)
})
;; Move right after self-inserting character in Picture mode.
(defun picture-movement-right { (picture-set-motion 0 1) })
;; Move left after self-inserting character in Picture mode.
(defun picture-movement-left { (picture-set-motion 0 -1) })
;; Move up after self-inserting character in Picture mode.
(defun picture-movement-up { (picture-set-motion -1 0) })
;; Move down after self-inserting character in Picture mode.
(defun picture-movement-down { (picture-set-motion 1 0) })
;; Move up and left after self-inserting character in Picture mode.
(defun picture-movement-nw { (picture-set-motion -1 -1) })
;; Move up and right after self-inserting character in Picture mode.
(defun picture-movement-ne { (picture-set-motion -1 1) })
;; Move down and left after self-inserting character in Picture mode.
(defun picture-movement-sw { (picture-set-motion 1 -1) })
;; Move down and right after self-inserting character in Picture mode.
(defun picture-movement-se { (picture-set-motion 1 1) })
;; Move in direction of picture-vertical-step and picture-horizontal-step.
;; With ARG do it that many times.
;; Useful for delineating rectangles in conjunction with diagonal
;; picture motion.
;; Do apropos picture-movement to see commands which control motion.
(defun picture-move
{
(int col)
(col (+ (current-column) (* picture-horizontal-step (arg-prefix))))
(case
(< picture-vertical-step 0) (picture-move-up)
(> picture-vertical-step 0) (picture-move-down)
)
(move-to-column-force col)
})
;; Move point in direction opposite of current picture motion in Picture mode.
;; With ARG do it that many times.
;; Useful for delineating rectangles in conjunction with diagonal
;; picture motion.
;; Do apropos picture-movement to see commands which control motion.
(defun picture-move-reverse
{
(*= picture-vertical-step -1)(*= picture-horizontal-step -1)
(picture-move)
(*= picture-vertical-step -1)(*= picture-horizontal-step -1)
})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;; Picture insertion and deletion ;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Insert character in place of character previously at the cursor.
;; The cursor then moves in the direction previously specified
;; with the picture-movement- commands.
;; Do apropos picture-movement to see those commands.
(defun picture-insert (string c)(int n) HIDDEN
{
(int i)
(i n)
(while (> i 0)
{
(-= i 1)
(move-to-column-force (+ 1 (current-column))) ; break up any tabs
(delete-previous-character)
(insert-text c)
(previous-character)
(arg-prefix 1)(picture-move)
})
})
(defun picture-self-insert
{
(string key 10)
(picture-insert (asc (key-pressed) key) (arg-prefix))
})
;; Clear out ARG columns after point without moving.
(defun picture-clear-column
{
(int col)
(set-mark)(msg "")
(col (current-column (+ (current-column) (arg-prefix))))
(erase-region)(to-col col)
(exchange-dot-and-mark)
})
;; Clear out ARG columns before point, moving back over them.
(defun picture-backward-clear-column
{
(if (== 1 (current-column)) (done)) ; no op if at begining of line
(move-to-column-force (- (current-column) (arg-prefix)))
(picture-clear-column)
})
;; Clear out rest of line; if at end of line, advance to next line.
;; Cleared-out line text goes into the kill ring, as do
;; newlines that are advanced over.
;; With argument, clear out (and save in kill ring) that many lines.
(defun picture-clear-line
{
(int n)
(if (arg-flag)
{
(arg-prefix (n (arg-prefix))) (kill-line)
(arg-prefix n)(newline)
}
{
(if (looking-at '.+$')(kill-line))
(append-to-register 0 "^J") ; tack a newline to end of killbuffer
(forward-line 1)
}
)
})
;; Move to the beginning of the following line.
;; With argument, moves that many lines (up, if negative argument).
;; Always moves to the beginning of a line.
(defun picture-newline
{
(int n)
(if (< (n (arg-prefix)) 0) ; negative arg => move up
(forward-line n)